import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemUserApi {
  export interface SystemUser {
    [key: string]: any;
    id: number;
    username: string;
    phone: string;
    sex: number;
    email: string;
    remark?: string;
    status: 0 | 1;
  }
}

/**
 * 获取用户列表数据
 */
async function getUserList(
  pageNum: number,
  pageSize: number,
  filterData: Recordable<any>,
) {
  return requestClient.post<Array<SystemUserApi.SystemUser>>('/user/listUser', {
    pageNum,
    pageSize,
    filterData,
  });
}

/**
 * 创建用户
 * @param data 用户数据
 */
async function createUser(data: Omit<SystemUserApi.SystemUser, 'id'>) {
  return requestClient.post('/user/addUser', data);
}

/**
 * 更新用户
 *
 * @param id 用户 ID
 * @param data 用户数据
 */
async function updateUser(
  id: string,
  data: Omit<SystemUserApi.SystemUser, 'id'>,
) {
  // 设置主键id
  data.id = id;
  return requestClient.post(`/user/editUser`, data);
}

/**
 * 删除用户
 * @param id 用户 ID
 */
async function deleteUser(id: string) {
  return requestClient.post(`/user/deleteUser?id=${id}`);
}

/**
 * 启用/禁用角色
 */
async function enableUser(id: string, status: number) {
  return requestClient.post(`/user/enableUser?id=${id}&status=${status}`);
}

export { createUser, deleteUser, enableUser, getUserList, updateUser };
